package com.goldman.http.common.s2s;

import lombok.Builder;
import lombok.Data;

import java.util.Map;
import java.util.Set;

@Data
@Builder
public class S2SOption {
    private Map<String, String> headers;
    private Map<String, String> params;
    private ContentType contentType = ContentType.JSON;
    // 毫秒
    private int timeout;
    // 忽略错误码
    private Set<Integer> ignoreErrCodeSet;

    public boolean isIgnoreErrCode(int code) {
        if (ignoreErrCodeSet != null && ignoreErrCodeSet.contains(code))
            return true;
        return false;
    }

    public boolean paramIsNotEmpty() {
        return this.getParams() != null && this.getParams().keySet().size() > 0;
    }

    public boolean headerIsNotEmpty() {
        return this.getHeaders() != null && this.getHeaders().size() > 0;
    }

    public enum ContentType {
        JSON("application/json;charset=utf-8"),
        XML("text/xml;charset=utf-8"),
        TEXT("text/plain;charset=utf-8"),
        HTML("text/html;charset=utf-8");
        private String content;

        ContentType(String content) {
            this.content = content;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }
    }


}
